package com.quexin.pickmedialib;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.ArrayList;
import java.util.List;

public class PickerMediaParameter implements Parcelable {

    public static final String PICKER_MEDIA = "PickerMediaOptions";
    public static final String PICKER_MEDIA_DATA = "PickerMedia";

    public static final int TYPE_PICTURE = 1;
    public static final int TYPE_VIDEO = 2;
    public static final int TYPE_AUDIO = 3;

    public static final int RESULT_OK = 1000;
    public static final int DEFAULT_REQUEST_CODE = 1001;

    private int type = TYPE_PICTURE;
    private int min = 1;
    private int max = 1;
    private int requestCode = DEFAULT_REQUEST_CODE;
    private final ArrayList<MediaModel> pickerData = new ArrayList<>();

    public PickerMediaParameter() {

    }

    public int getType() {
        return type;
    }

    public int getMin() {
        return min;
    }

    public int getMax() {
        return max;
    }

    public int getRequestCode() {
        return requestCode;
    }

    public ArrayList<MediaModel> getPickerData() {
        return pickerData;
    }

    public PickerMediaParameter picture() {
        type = TYPE_PICTURE;
        return this;
    }

    public PickerMediaParameter video() {
        type = TYPE_VIDEO;
        return this;
    }

    public PickerMediaParameter audio() {
        type = TYPE_AUDIO;
        return this;
    }

    public PickerMediaParameter min(int min) {
        this.min = min;
        return this;
    }

    public PickerMediaParameter max(int max) {
        this.max = max;
        return this;
    }

    public PickerMediaParameter pickerData(List<MediaModel> pickerData) {
        this.pickerData.clear();
        this.pickerData.addAll(pickerData);
        return this;
    }

    public PickerMediaParameter requestCode(int requestCode) {
        this.requestCode = requestCode;
        return this;
    }

    protected PickerMediaParameter(Parcel in) {
        type = in.readInt();
        min = in.readInt();
        max = in.readInt();
    }

    public static final Creator<PickerMediaParameter> CREATOR = new Creator<PickerMediaParameter>() {
        @Override
        public PickerMediaParameter createFromParcel(Parcel in) {
            return new PickerMediaParameter(in);
        }

        @Override
        public PickerMediaParameter[] newArray(int size) {
            return new PickerMediaParameter[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(type);
        dest.writeInt(min);
        dest.writeInt(max);
    }
}
